<template>
  <div>
    <!-- 页头 -->
    <Header></Header>
    <!-- /页头 -->
    <div class="passport-container">
      <div class="passport-container-inner">
        <div class="passport-notes">
          <div data-v-4cedbcf6="" class="notes">
            <h4 data-v-4cedbcf6="">Xerox Alto</h4>
            <p data-v-4cedbcf6="" id="scrollP" style="-webkit-box-orient: vertical; cursor: pointer;">1973 年 3 月 1
              日，Xerox Alto 诞生。Xerox Alto（施乐奥多）由施乐 PARC 研发，查尔斯·萨克尔担任项目负责人。Alto
              是现代个人计算机的鼻祖，首次使用桌面比拟和鼠标驱动，是最早使用图形用户界面的个人计算机。SUN 工作站和 Macintosh 等均参考了 Alto 的设计。</p> <span
              data-v-4cedbcf6="" class=""><i data-v-4cedbcf6="" class=""></i>2281
            </span>
          </div>
        </div>
        <!--登录标签-->
        <div class="passport-main">
          <div class="welcome_tips">
            <span>终于等到你～</span>
            <img src="../assets/loginlogo.png" />
          </div>
          <!-- 登录表单 -->
          <div class="login-box">
            <div class="login-title">
              <span>密码登录</span>
            </div>
            <div class="login-main">
              <el-form>
                <el-form-item>
                  <el-input v-model="UserInfo.idCard" class="login-style" placeholder="手机号/邮箱/用户名" clearable></el-input>
                </el-form-item>
                <el-form-item>
                  <el-input v-model="UserInfo.password" class="login-style" placeholder="密码" clearable show-password>
                  </el-input>
                </el-form-item>
                <el-form-item>
                  <el-button class="login-style" type="primary" @click="submitForm()">登录</el-button>
                </el-form-item>
              </el-form>
            </div>
            <div class="tip">
              <p>还未注册？请点击
                <span id="login_btn">
                  <a href="#/register">
                    <router-link :to="{name:'Register'}">注册</router-link>
                  </a>
                </span>
              </p>
            </div>
          </div>
          <!-- /登录表单 -->
        </div>
        <!--/登录标签-->
      </div>
    </div>
    <!-- 页脚 -->
    <Footer></Footer>
    <!-- /页脚 -->
  </div>
</template>

<script>
  import token from "../components/token.vue"
  import Footer from "../components/Footer";
  import Header from "../components/Header";
  export default {
    name: "Login",
    data() {
      var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        } else {
          // if (this.ruleForm.checkPass !== '') {
          //   this.$refs.ruleForm.validateField('checkPass');
          // }
          // callback();
        }
      };
      var username = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入用户名'));
        }
      };

      var phone = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入电话'));
        }
      };

      return {
        UserInfo: {
          idCard: '',
          password: ''
        },
        rules: {
          username: [{
            validator: username,
            trigger: 'blur'
          }],
          phone: [{
            validator: phone,
            trigger: 'blur'
          }],
          pass: [{
            validator: validatePass,
            trigger: 'blur'
          }],
        }
      };
    },
    methods: {
      resetForm() {
        this.UserInfo.idCard = ''
        this.UserInfo.password = ''
      },
      submitForm() {
        let _this = this
        this.$axios.post("http://localhost:8087/user/login", this.UserInfo).then(function(res) {
          if (res.data != -1) {
            _this.$message({
              message: '登陆成功~',
              type: 'success'
            });
            _this.$router.push({
              name: 'Index',
              query: {
                id: res.data
              }
            })
            localStorage.setItem("id", res.data)
            token.type = 1;
            console.log("登录：" + localStorage.getItem("id"))
          } else {
            _this.$message.error('可能是账户或密码错误，登录失败呢');
          }
        })
        this.resetForm()
      }
    },
    components: {
      Footer,
      Header
    }
  }
</script>

<style scoped>
  .passport-container {
    width: 100%;
    height: calc(100% - 140px);
    background: url(../assets/loginbg.jpg) no-repeat 50%;
    background-size: cover;
    min-height: 800px;
    position: relative;
  }

  @media screen and (max-width: 1920px) and (min-width: 1440px) .passport-container .passport-container-inner {
    width: calc(100% - 240px);
  }

  .passport-container .passport-container-inner {
    background: transparent;
    position: absolute;
    top: 50%;
    left: 50%;
    height: 520px;
    transform: translate(-50%, -55%);
    clear: both;
    max-width: 1520px;
  }

  .passport-container .passport-container-inner .passport-notes {
    width: 419px;
    height: 100%;
    float: left;
  }

  .passport-container .passport-container-inner .passport-notes .notes {
    width: 100%;
    height: 100%;
    padding: 0;
  }

  .notes[data-v-4cedbcf6] {
    width: 340px;
    height: 500px;
    padding: 40px;
    font-size: 16px;
    position: relative;
    float: left;
  }

  .passport-container .passport-container-inner .passport-notes .notes h4 {
    margin: 130px 0 8px;
  }

  .notes h4[data-v-4cedbcf6] {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 16px;
    line-height: 34px;
    height: 34px;
    font-size: 28px;
    color: #fff !important;
    font-weight: 400;
    margin-bottom: 24px;
  }

  .notes p[data-v-4cedbcf6] {
    color: #fff !important;
    line-height: 34px;
    height: 246px;
    overflow-y: auto;
  }

  .passport-container .passport-container-inner .passport-notes .notes span {
    left: 0;
  }

  .passport-container .passport-container-inner {
    width: calc(100% - 240px);
  }

  .notes span[data-v-4cedbcf6] {
    position: absolute;
    box-sizing: border-box;
    min-width: 120px;
    height: 40px;
    padding: 0 10px;
    color: #fc5531;
    text-align: center;
    line-height: 40px;
    border-radius: 24px 24px;
    border: 1px solid #fc5531;
    left: 40px;
    bottom: 40px;
    cursor: pointer;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
  }

  .passport-main {
    position: relative;
    width: 410px;
    height: 468px;
    margin-top: 52px;
    float: right;
  }

  .welcome_tips {
    position: absolute;
    top: -52px;
    right: 40px;
  }

  .welcome_tips span {
    position: relative;
    top: -15px;
    left: 0;
    height: 16px;
    font-size: 12px;
    font-weight: 400;
    color: #fff;
    line-height: 16px;
    text-shadow: 0 2px 2px #555666;
  }

  .welcome_tips img {
    width: 56px;
    height: 56px;
  }

  .login-box {
    width: 100%;
    height: 100%;
    border-radius: 2px 2px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
  }

  .login-main {
    margin-top: 30px;
    width: 90%;
    height: 60%;
  }

  .login-style {
    width: 100%;
  }

  .tip {
    height: 24px;
    font-size: 12px;
    font-weight: 400;
    color: #999aaa;
    line-height: 24px;
  }

  a {
    text-decoration: none !important;
    color: #000000;
  }

  .login-title {
    width: 90%;
    height: 50px;
    text-align: center;
    line-height: 50px;
    font-size: 18px;
    letter-spacing: 2px;
  }
</style>
